{template "header.html"}

<div class="note note-danger">
    <p><a href="javascript:dr_update_cache_all();">{dr_lang('操作之前请更新下全站缓存')}</a></p>
</div>

<div class="portlet light bordered">
    <div class="portlet-title tabbable-line">
        <ul class="nav nav-tabs" style="float:left;">
            <li class="{if $page==0}active{/if}">
                <a href="#tab_0" data-toggle="tab" onclick="$('#dr_page').val('0')"> <i class="fa fa-database"></i> {dr_lang('内容批量替换')} </a>
            </li>
            <li class="{if $page==3}active{/if}">
                <a href="#tab_3" data-toggle="tab" onclick="$('#dr_page').val('3')"> <i class="fa fa-edit"></i> {dr_lang('内容批量设置')} </a>
            </li>
            <li class="{if $page==2}active{/if}">
                <a href="#tab_2" data-toggle="tab" onclick="$('#dr_page').val('2')"> <i class="fa fa-th-large"></i> {dr_lang('内容批量执行')} </a>
            </li>
            <li class="{if $page==1}active{/if}">
                <a href="#tab_1" data-toggle="tab" onclick="$('#dr_page').val('1')"> <i class="fa fa-code"></i> {dr_lang('执行SQL')} </a>
            </li>
        </ul>
    </div>
    <div class="portlet-body form">
        <div class="tab-content">

            <div class="tab-pane {if $page==0}active{/if}" id="tab_0">

                <form action="" class="form-horizontal" method="post" id="replaceform">
                    {$form}
                    <div class="form-body">

                        <div class="form-group row">
                            <label class="col-md-2 control-label"> {dr_lang('表名称')} </label>
                            <div class="col-md-9">
                                <label><select name="bm" class="form-control" onchange="dr_fd(this.value)">
                                    <option value="0">{dr_lang('选择表')}</option>
                                    {loop $tables $t}
                                    <option value="{$t.Name}" {if $t.Name == $table} selected{/if}>{$t.Name}{if $t.Comment}（{$t.Comment}）{/if}</option>
                                    {/loop}
                                </select></label>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('待替换字段')}</label>
                            <div class="col-md-9">
                                <label id="dr_fd"><label><select class="form-control">
                                    <option value="0">{dr_lang('没有选择表')}</option>
                                </select></label></label>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('被替换内容')}</label>
                            <div class="col-md-9">
                                <textarea class="form-control" style="height:100px" name="t1"></textarea>
                                <p style="padding-top:9px;" class="help-block"> {dr_lang('设置被替换的字符内容')} </p>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('替换后的内容')}</label>
                            <div class="col-md-9">
                                <textarea class="form-control" style="height:100px" name="t2"></textarea>
                                <p style="padding-top:9px;" class="help-block"> {dr_lang('将上面设置的被替换的字符替换成新的字符')} </p>

                            </div>
                        </div>


                        <div class="form-actions">
                            <label class="col-md-2 control-label">&nbsp;</label>
                            <div class="col-md-9" style="padding-left: 5px;">
                                <button type="button" onclick="dr_submit_post_todo('replaceform', '{dr_url('module_content/edit')}')" class="btn blue"> <i class="fa fa-database"></i> {dr_lang('立即执行')}</button>
                            </div>
                        </div>
                    </div>
                </form>


           </div>


            <div class="tab-pane {if $page==3}active{/if}" id="tab_3">

                <form action="" class="form-horizontal" method="post" id="editform">
                    {$form}
                    <div class="form-body">

                        <div class="form-group row">
                            <label class="col-md-2 control-label"> {dr_lang('表名称')} </label>
                            <div class="col-md-9">
                                <label><select name="bm" class="form-control" onchange="dr_sz(this.value)">
                                    <option value="0">{dr_lang('选择表')}</option>
                                    {loop $tables $t}
                                    <option value="{$t.Name}" {if $t.Name == $table} selected{/if}>{$t.Name}{if $t.Comment}（{$t.Comment}）{/if}</option>
                                    {/loop}
                                </select></label>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('待设置字段')}</label>
                            <div class="col-md-9">
                                <label id="dr_sz"><label><select class="form-control">
                                    <option value="0">{dr_lang('没有选择表')}</option>
                                </select></label></label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('修改方式')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="ms" value="0" checked /> {dr_lang('完全替换指定值')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="ms" value="1"  /> {dr_lang('将新值插入在原值之前')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="ms" value="2"  /> {dr_lang('将新值插入在原值之后')} <span></span></label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('执行条件')}</label>
                            <div class="col-md-9">
                                <textarea class="form-control" style="height:100px" name="t1"></textarea>
                                <p style="padding-top:9px;" class="help-block"> {dr_lang('设置批量替换的条件SQL语句，留空表示全部替换')} </p>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('设置新的值')}</label>
                            <div class="col-md-9">
                                <textarea class="form-control" style="height:100px" name="t2"></textarea>
                                <p style="padding-top:9px;" class="help-block"> {dr_lang('设置修改后的字符内容')} </p>
                            </div>
                        </div>


                        <div class="form-actions">
                            <label class="col-md-2 control-label">&nbsp;</label>
                            <div class="col-md-9" style="padding-left: 5px;">
                                <button type="button" onclick="dr_submit_post_todo('editform', '{dr_url('module_content/all_edit')}')" class="btn blue"> <i class="fa fa-edit"></i> {dr_lang('立即执行')}</button>
                            </div>
                        </div>
                    </div>
                </form>


            </div>

            <div class="tab-pane {if $page==2}active{/if}" id="tab_2">

                <div class="table-scrollable">
                <table style="margin-top: 30px;" class="table table-striped table-bordered table-hover table-checkable dataTable">
                    <thead>
                    <tr class="heading">
                        <th width="50"> </th>
                        <th width="180"> {dr_lang('内容模块')} </th>
                        <th>{dr_lang('批量操作')}</th>
                    </tr>
                    </thead>
                    <tbody>
                    {php $i=1;}
                    {loop $module $m}
                    <tr class="heading">
                        <td>
                            {$i}
                        </td>
                        <td>
                            <i class="{dr_icon($m['icon'])} font-dark"></i> {dr_lang($m['name'])}
                        </td>
                        <td>
                            <label><button type="button" onclick="dr_iframe_show('{dr_lang('批量操作')}', '{dr_url('module_content/url_edit')}&mid={$m.dirname}')" class="btn blue btn-xs"> <i class="fa fa-refresh"></i> {dr_lang('更新内容URL地址')} </button></label>
                            <label><button type="button" onclick="dr_iframe_show('{dr_lang('批量操作')}', '{dr_url('module_content/desc_index')}&mid={$m.dirname}')" class="btn drak btn-xs"> <i class="fa fa-th-large"></i> {dr_lang('提取描述字段')} </button></label>
                            <label><button type="button" onclick="dr_iframe_show('{dr_lang('批量操作')}', '{dr_url('module_content/thumb_index')}&mid={$m.dirname}')" class="btn green btn-xs"> <i class="fa fa-photo"></i> {dr_lang('提取缩略图')} </button></label>
                            <label><button type="button" onclick="dr_iframe_show('{dr_lang('批量操作')}', '{dr_url('module_content/tag_index')}&mid={$m.dirname}')" class="btn yellow btn-xs"> <i class="fa fa-tag"></i> {dr_lang('提取关键词')} </button></label>
                            <label><button type="button" onclick="dr_iframe_show('{dr_lang('批量操作')}', '{dr_url('module_content/del_index')}&mid={$m.dirname}')" class="btn red btn-xs"> <i class="fa fa-trash"></i> {dr_lang('彻底删除内容')} </button></label>
                            <label><button type="button" onclick="dr_iframe_show('{dr_lang('批量操作')}', '{dr_url('module_content/cat_index')}&mid={$m.dirname}')" class="btn green btn-xs"> <i class="fa fa-reorder"></i> {dr_lang('变更栏目')} </button></label>

                        </td>
                    </tr>
                    {php $i++;}
                    {/loop}
                    </tbody>
                </table>
                </div>

            </div>


            <div class="tab-pane {if $page==1}active{/if}" id="tab_1">

                <form action="" class="form-horizontal" method="post" id="sqlform">
                    {$form}
                    <div class="form-body">


                        <div class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('SQL语句')}</label>
                            <div class="col-md-9">
                                <textarea id="sql" class="form-control" style="height:200px" name="sql"></textarea>
                                <p style="padding-top:9px;" class="help-block"> {dr_lang('只支持常用的SQL语句，复杂的SQL语句请使用phpmyadmin工具执行')} </p>
                            </div>
                        </div>

                        {if $sql_cache}
                        <div class="form-group row">
                            <label class="col-md-2 control-label " style="padding-top: 8px">{dr_lang('最近执行')}</label>
                            <div class="col-md-9">
                                <select class="form-control" onchange="$('#sql').val(this.value)">
                                    <option value="">--</option>
                                {loop $sql_cache $t}
                                    <option value="{$t}">{dr_strcut($t, 50)}</option>
                                {/loop}
                                </select>
                            </div>
                        </div>
                        {/if}

                        <div id="sql_result_id" class="form-group row">
                            <label class="col-md-2 control-label">{dr_lang('执行结果')}</label>
                            <div class="col-md-9" id="sql_result">

                            </div>
                        </div>


                        <div class="form-actions">
                            <label class="col-md-2 control-label">&nbsp;</label>
                            <div class="col-md-9" style="padding-left: 5px;">
                                <button type="button" onclick="dr_submit_sql_todo('sqlform', '{dr_url('module_content/sql_edit')}')" class="btn blue"> <i class="fa fa-database"></i> {dr_lang('立即执行')}</button>
                            </div>
                        </div>

                    </div>
                </form>
            </div>
        </div>
    </div>
</div>



<script>
    {if $table}
    dr_fd('{$table}');
    dr_sz('{$table}');
    {/if}
    function dr_fd(v) {
        $.ajax({type: "get",dataType:"json", url: "{dr_url('module_content/field_index')}&field={$field}&table="+v,
            success: function(json) {
                if (json.code == 1) {
                    $('#dr_fd').html(json.msg);
                } else {
                    dr_cmf_tips(0, json.msg);
                }
                return false;
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
            }
        });
    }
    function dr_sz(v) {
        $.ajax({type: "get",dataType:"json", url: "{dr_url('module_content/field_index')}&field={$field}&table="+v,
            success: function(json) {
                if (json.code == 1) {
                    $('#dr_sz').html(json.msg);
                } else {
                    dr_cmf_tips(0, json.msg);
                }
                return false;
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
            }
        });
    }
</script>

{template "footer.html"}